package com.gao.controller;

import com.gao.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
@RequestMapping("/consumer")
public class ConsumerController {

    @Autowired
    private RestTemplate restTemplate;

    private final String URL_PREFIX = "http://PROVIDER-DEPT/dept";   //这里配置 服务提供者的服务名


    @GetMapping("/dept/get/{id}")
    public Dept getDept(@PathVariable("id") Integer id) {
        return restTemplate.getForObject(URL_PREFIX + "/get/" + id, Dept.class);
    }

    @GetMapping("/dept/get/list")
    public List<Dept> getDeptList() {
        return restTemplate.getForObject(URL_PREFIX + "/get/list", List.class);
    }


    @PostMapping("/dept/add")
    public boolean addDept(@RequestBody Dept dept) {
        return restTemplate.postForObject(URL_PREFIX + "/add", dept, Boolean.class);
    }


}
